Some thoughtful data wrangling will be needed and it will be demonstrated in class — Do not expect a video.
Examine the data and the plot provided in undergraduate-admissions-statistics.pdf — this pdf was collected from the Northwestern Data Book webpage. As you can see they have overlaid two plot types on one another by using dual y-axes.
There is one major error they make with the bars in their graphic. Explain what it is.
Solution
The total number of applicants doesn’t align with the number reflected in the bar plot. For instance, in the 2002, it shows there were around 14,000 applicants but the plot shows that there were 20,000 applicants because it added the number of applicants plus the number of accepted students and the number of students that matriculated.
Using NU_admission_data.csv1, create two separate plots that display the same information instead of trying to put it all in one single plot — stack them using patchwork or cowplot.
Which approach do you find communicates the information better, the single dual y-axes plot or the two separate plot approach? Why?
Solution
The two separate plot approach communicates the information better than the single dual y-axes plot. A single dual y-axes plot is helpful when there are two corresponding values, such as metric system vs. imperial system. Plus, the dual y-axes plot, visually speaking, was very busy and it was hard to understand the information that was being portrayed. The two separate plot approach communicates the same information but does so in a way that makes sense to the viewer, by splitting the admissions data into two distinct plots. Furthermore, the two separate plot approach fixes some of the issues found in the dual y-axes plot, such as the total number of applicants not lining up with what is being shown on the bar graph.
Hints:
Form 4 datasets (helps you get organized, but not entirely necessary):
1 that has bar chart data,
1 that has bar chart label data,
1 that has line chart data, and
1 that has line chart labels
Consider using ggsave() to save the image with a fixed size so it is easier to pick font sizes.
Solution
Code
# data wranglingbar_data <- admin_data |>select(-contains('_rate')) |># - contains() == select all column that does not contain '_rate'pivot_longer(cols =-year,names_to ='category',values_to ='value' ) |>mutate(bar_labels =prettyNum(value, big.interval =',') )# building the plotbar_plot <- bar_data |>filter (year >=2002) |>ggplot(aes(year, value, fill = category)) +geom_col(mapping =aes(fill = category),width =0.5,position ='identity' )+geom_text(aes(label = bar_labels),size =1.5,color ='white',vjust =1,nudge_y =-200) +scale_x_continuous(name ='Entering Year', breaks =2002:2022,expand =c(0, 0.25) #L is multiplicative, R is additive ) +scale_y_continuous(name ='Applications',expand =c(0, 0),limits =c(0, 70000),breaks =seq(0, 70000, 10000), labels = scales::label_comma() ) +scale_fill_manual(name =NULL,limits =c('applications', 'admitted_students', 'matriculants'),labels =c('Applications', 'Admitted Students', 'Matriculants'),values =c('#B6ACD1', '#836EAA', '#4E28A4') ) +theme_classic() +theme(legend.justification =c(0.5, 1), legend.position ='inside', legend.position.inside =c(0.5,1),legend.direction ='horizontal',plot.title =element_text(hjust =0.5) ) +ggtitle('Northwestern University \nUndergraduate Admissions 2002-2022')